// 通用方法
export function getCurrentTime(){
  //获取当前时间并打印
  var _this = this;
  let yy = new Date().getFullYear();
  let mm = new Date().getMonth()+1;
  let dd = new Date().getDate();
  let hh = new Date().getHours();
  let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
  let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
  _this.gettime = yy+'/'+mm+'/'+dd+' '+hh+':'+mf+':'+ss;
  console.log(_this.gettime)
}

export function transformTimestamp(timestamp){//时间对象转字符串
  let a = new Date(timestamp).getTime();
  const date = new Date(a);
  const Y = date.getFullYear() + '-';
  const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  const D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
  const h = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours()) + ':';
  const m = (date.getMinutes() <10 ? '0'+date.getMinutes() : date.getMinutes()) + ':' ;
  const s = date.getSeconds(); // 秒
  const dateString = Y + M + D + h + m + s;
  // console.log('dateString', dateString); // > dateString 2021-07-06 14:23
  return dateString;
}



export default {
  getCurrentTime,
  transformTimestamp
}
